import time

from selenium import webdriver
from zoukao3.Base.Base import Base
from selenium.webdriver.common.by import By
class Page1(Base):
    # 点击登录按钮
    login_loc=(By.LINK_TEXT,'登录')
    # 输入用户名
    username_loc=(By.NAME,'username')
    # 输入密码
    password_loc=(By.NAME,'password')
    # 点击登录
    loginbtn_loc=(By.CLASS_NAME,'finish-btn')
    # 断言欢迎回来
    dy1_loc=(By.XPATH,'/html/body/div[1]/div/div[2]/ul/li[1]/a')
    # 地址管理
    adress_loc=(By.CLASS_NAME,'bestow')
    # 添加地址
    add_loc=(By.XPATH,'/html/body/div[5]/div[2]/div/div[1]/a')
    diqu1_loc=(By.XPATH,'//*[@id="layui-layer1"]/div[2]/div/div/form/div[1]/div[1]/div/div/input')
    diqu2_loc=(By.XPATH,'//*[@id="layui-layer1"]/div[2]/div/div/form/div[1]/div[2]/div/div/input')
    diqu3_loc=(By.XPATH,'//*[@id="layui-layer1"]/div[2]/div/div/form/div[1]/div[3]/div/div/input')

    # 收货人姓名
    name_loc=(By.NAME,'accept_name')
    # 收货人电话
    phone_loc=(By.NAME,'mobile')
    # 立即提交
    submit_loc=(By.CLASS_NAME,'layui-btn')

    def login(self):
        self.click(self.login_loc)

    def username(self):
        self.send_keys(self.username_loc, '18986670716')

    def password(self):
        self.send_keys(self.password_loc, 'a123456')

    def loginbtn(self):
        self.click(self.loginbtn_loc)

    def dy1(self):
        return self.text(self.dy1_loc)

    def adress(self):
        self.click(self.adress_loc)

    def add(self):
        self.click(self.add_loc)

    def diqu1(self):
        self.select_value(self.diqu1_loc, '北京市')

    def diqu2(self):
        self.select_value(self.diqu2_loc, '北京市')

    def diqu3(self):
        self.select_value(self.diqu3_loc, '东城区')

    def name(self):
        self.send_keys(self.name_loc,'zzz')

    def phone(self):
        self.send_keys(self.phone_loc,'18986670766')

    def submit(self):
        self.click(self.submit_loc)
    # 业务逻辑
    def luoji_02(self):
        self.open_url('http://10.59.9.12:7001/')
        self.login()
        self.username()
        self.password()
        time.sleep(8)
        self.loginbtn()
        time.sleep(5)
        print(self.dy1())
        assert  '欢迎回来，18986670716' in self.dy1()
        time.sleep(3)
        self.adress()
        self.add()
        try:
            self.diqu1()
            self.diqu2()
            self.diqu3()
            self.name()
            self.phone()
            self.submit()
        except BlockingIOError as e:
            print(e)